<?php
namespace App\Utils;

use App\Models\MConfig;
use Cache;

class ComUtil
{

    /**
     * 读取配置信息到缓存当中
     * @param $title    配置标题
     * @param $need     是否强制刷新缓存
     */
    public static function initConfig2Cache($title, $need = false)
    {
        //已有缓存并且无需强制刷新就直接返回
        if (Cache::has($title) && $need == false) {
            return;
        }

        $config = MConfig::getKV($title);
        if (!empty($config)) {
            foreach (unserialize($config->kv) as $k => $v) {
                Cache::forever($k, $v);
            }
            Cache::forever($title, $title);
        }
    }

}